//
//  MenuGame.m
//  BalanceBall
//
//  Created by macpro on 2/6/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "MenuGame.h"
#import "SinglePlayer.h"

@implementation MenuGame

+(id) scene
{
	CCScene *scene = [CCScene node];
	MenuGame *layer = [MenuGame node];
	[scene addChild: layer];
	return scene;
}

-(id) init
{
	if( (self=[super init] )) {
        
		CCSprite *background = [CCSprite spriteWithFile:@"background_home.jpg"];
		CGSize winSize = [[CCDirector sharedDirector] winSize];
		[CCMenuItemFont setFontSize:50];
		[CCMenuItemFont setFontName: @"Marker Felt"];
        
        CCMenuItemImage *item1 = [CCMenuItemImage itemFromNormalImage:@"single_btn.png" selectedImage:@"single_btn_selected.png" disabledImage:@"single_btn.png" target:self selector:@selector(playSingle)];
        CCMenuItemImage *item2 = [CCMenuItemImage itemFromNormalImage:@"multi_btn.png" selectedImage:@"multi_btn_selected.png" disabledImage:@"multi_btn.png" target:self selector:@selector(playMulti)];
        CCMenuItemImage *item3 = [CCMenuItemImage itemFromNormalImage:@"help_btn.png" selectedImage:@"help_btn_selected.png" disabledImage:@"help_btn.png" target:self selector:@selector(openHelp)];
        
		CCMenu *frontMenu = [CCMenu menuWithItems: item1, item2, item3, nil];
		frontMenu.color = ccc3(255,215,0);
		[frontMenu alignItemsVertically];
        [frontMenu alignItemsVerticallyWithPadding:40];
		
//		// elastic effect
//		CGSize s = [[CCDirector sharedDirector] winSize];
//		int i=0;
//		for( CCNode *child in [frontMenu children] ) {
//			CGPoint dstPoint = child.position;
//			int offset = s.width/2 + 50;
//			if( i % 2 == 0)
//				offset = -offset;
//			child.position = ccp( dstPoint.x + offset, dstPoint.y);
//			[child runAction: 
//			 [CCEaseElasticOut actionWithAction:
//			  [CCMoveBy actionWithDuration:2 position:ccp(dstPoint.x - offset,0)]
//										 period: 0.35f]
//			 ];
//			i++;
//		}
        
		
		background.position = ccp(winSize.width/2, winSize.height/2);
		[self addChild: background];
		[self addChild: frontMenu];
		
	}
	return self;
}

-(void) playSingle{
    [[CCDirector sharedDirector] replaceScene:[CCTransitionMoveInR transitionWithDuration:0.5 scene:[SinglePlayer scene]]];
}

-(void) playMulti{
    
}

-(void) openHelp{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"* Click on one of the blue/red ball and hold touch down\n* Drag touch to choose speed and direction\n* Release touch to shoot\n* Set game will end when all blue/red ball off the screen" delegate:nil cancelButtonTitle:@"Back" otherButtonTitles: nil];
    [alert show];
    [alert release];
    
    NSArray *subViewArray = alert.subviews;
    for(int x=0;x<[subViewArray count];x++){
        if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
        {
            UILabel *label = [subViewArray objectAtIndex:x];
            label.textAlignment = UITextAlignmentLeft;
        }
        
    }
}

- (void) dealloc
{
	[super dealloc];
}

@end
